package org.monklypse.jme2.demoapp.views;

import com.jme.light.DirectionalLight;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.state.LightState;

/**
 * Implementation that introduce simple lightning
 * 
 * @author Tareq doufish
 */
public class Demo2Implementor extends DemoImplementor {

	/** Light state for the environment */
    private LightState lightState;
    
    /** The sub light for the environment */
    private DirectionalLight sunLight;
    
	public void simpleSetup() {
		super.simpleSetup();
		
		// creating some lights here.
		configureWorldLight();
	}
	
	public void configureWorldLight() {
		/** Attach the light to a lightState and the lightState to rootNode. */
		lightState = renderer.createLightState();
		lightState.setEnabled(true);

		// Configure the lights in the system.
		configurePointLight();
		configureSunLight();

		rootNode.setRenderState(lightState);
	}

	protected void configureSunLight() {
		sunLight = new DirectionalLight();
		sunLight.setEnabled(true);
		sunLight.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
		sunLight.setAmbient(new ColorRGBA(.2f, .2f, .2f, .3f));
		sunLight.setDirection(new Vector3f(-1F, -1F, 1F));
		sunLight.setShadowCaster(true);
		lightState.attach(sunLight);
		lightState.setGlobalAmbient(new ColorRGBA(0.6f, 0.6f, 0.6f, 1.0f));
	}

	protected void configurePointLight() {
		PointLight light = new PointLight();
		light.setDiffuse(new ColorRGBA(0.75f, 0.75f, 0.75f, 0.75f));
		light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
		light.setLocation(new Vector3f(100, 100, 100));
		light.setEnabled(true);
		lightState.attach(light);
	}

	public boolean isLightEnabled() {
		boolean succ = false;
		if (lightState != null && lightState.isEnabled()) {
			succ = true;
		}
		return succ;
	}

	public boolean isSunLightEnabled() {
		return lightState.isEnabled() && sunLight.isEnabled();
	}

	public DirectionalLight getSunLight() {
		return sunLight;
	}

	public LightState getLightState() {
		return lightState;
	}
    
	public Node getRootNode() { 
		return rootNode;
	}
	
}
